package com.yanqu.road.server.cmd.newmonopolymkt;

import com.yanqu.road.entity.systemgroup.ResourceServerGroup;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Cmd(code = GameProtocol.S_CROSS_NEW_MONOPOLY_MARKET_SYNC_INNER_GROUP_FROM_CROSS, desc = "大、中、小跨服分组同步")
public class NewMonopolyMarketInnerGroupSyncFromCorss implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {

        NewMonopolyMarketProto.NewMonopolyMarketInnerGroupSync msg = NewMonopolyMarketProto.NewMonopolyMarketInnerGroupSync.parseFrom(yanQuMessage.getBytes());

        int weekId = msg.getWeekId();

        Map<Integer, ResourceServerGroup> groupMap = new HashMap<>();
        for (NewMonopolyMarketProto.NewMonopolyMarketInnerGroupTemp groupTemp : msg.getGroupList()) {
            ResourceServerGroup serverGroup = new ResourceServerGroup();
            serverGroup.setGroupId(groupTemp.getGroupId());
            serverGroup.setResType(groupTemp.getResType());
            serverGroup.setGroupType(groupTemp.getGroupType());
            serverGroup.setServerList(new ArrayList<>(groupTemp.getServerIdList()));
            groupMap.put(groupTemp.getGroupId(), serverGroup);
        }
        NewMonopolyMarketMgr.syncInnerResourceServerGroup(weekId, groupMap);

    }
}
